package cn.admin.spring.web;

import cn.admin.spring.SpringRootConfigure;
import cn.admin.spring.mvc.SpringMvcConfig;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.Filter;

/**
 * @Author: 毛苏宇
 * @Description: 相当于web.xml配置
 * @Date: Create in 11:50 2019/4/26
 */
public class WebXmlConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     * 加载Spring配置
     *
     * @return
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringRootConfigure.class};
    }

    /**
     * webmvc配置
     *
     * @return
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    /**
     * 配置DispatcherServlet前端控制器
     *
     * @return
     */
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    /**
     * 配置过滤器,设置编码格式
     *
     * @return
     */
    protected Filter[] getServletFilters() {
        //字符编码
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return new Filter[]{characterEncodingFilter};
    }


}
